<template>
  <div class="blur-view-wrapper">
    <div class="blur-view-container">
      <div
        v-if="image"
        class="blur-image"
        :style="{
          filter: `blur(${blurValue})`,
          backgroundImage: `url(${image})`
        }"
      ></div>
      <div
        v-if="color"
        class="blur-color"
        :style="{
          filter: `blur(${blurValue})`,
          backgroundColor: color,
          opacity
        }"
      ></div>
      <div class="blur-view-content">
        <slot></slot>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "BlurView",
  props: {
    // 模糊值
    blur: {
      type: [Number, String],
      default: 10
    },
    image: {
      type: String,
      default: ""
    },
    color: {
      type: String,
      default: ""
    },
    opacity: {
      type: Number,
      default: 0.3
    }
  },
  computed: {
    blurValue() {
      const { blur } = this;
      return typeof blur === "string" ? blur : `${blur}px`;
    }
  }
};
</script>

<style lang="less">
.full {
  width: 100%;
  height: 100%;
}

.blur-view-wrapper {
  .blur-view-container {
    .full;
    position: relative;

    .blur-view-content {
      .full;
      position: relative;
      z-index: 15;
    }

    .blur-image,
    .blur-color {
      position: absolute;
      top: 0;
      left: 0;
      .full;
      transform: scale(1.5);
    }

    .blur-image {
      background-size: cover;
      background-position: center center;
      z-index: 5;
    }

    .blur-color {
      z-index: 10;
      opacity: 0.3;
    }
  }
}
</style>
